<?php
require_once "common/jssdk.php";
require_once "common/Utils.php";
require_once "common/logUtils.php";
$jssdk = new JSSDK(null, null);
$log = new logUtils();

$appid = $jssdk -> getAppId();
$secret = $jssdk -> getAppSecret();
$code = $_GET["code"];
$get_token_url = 'https://api.weixin.qq.com/sns/oauth2/access_token?appid=' . $appid . '&secret=' . $secret . '&code=' . $code . '&grant_type=authorization_code';

$json_obj = json_decode(Utils::curl_get($get_token_url), true);
print_r($json_obj);
//根据openid和access_token查询用户信息
$access_token = $json_obj['access_token'];
$openid = $json_obj['openid'];
$get_user_info_url = 'https://api.weixin.qq.com/sns/userinfo?access_token=' . $access_token . '&openid=' . $openid . '&lang=zh_CN';

//解析json
$user_obj = json_decode(Utils::curl_get($get_user_info_url), true);
$_SESSION['user'] = $user_obj;
//print_r($user_obj);
$log -> write($_GET["r"]);
echo $_GET["r"];
